import { mapState } from "vuex";

//  minxin.js
const mixin = {
  data() {
    return {
      titleDate: "",
      titleTime: "",
      startTime: "",
      endTime: "",
      startTimeDate: "",
      endTimeDate: "",
      dateType: "HOUR",
      type: "d",
      mouthDay: 0
    };
  },
  computed: {
    tabColor() {
      return this.darkMode ? "#5291FF" : "#0a59f7";
    }
  },
  methods: {
    allDays(year) {
      let leapYear = false,
        sum_day = 0,
        month_arr = [4, 6, 9, 11];
      if (year % 100 === 0) {
        // 年份是整百
        leapYear = year % 400 === 0;
      } else {
        leapYear = year % 4 === 0;
      }
      // 下面计算每个月的天数
      for (let i = 1; i < 13; i++) {
        if (i === 2) {
          sum_day += leapYear ? 29 : 28;
        } else if (month_arr.includes(i)) {
          sum_day += 30;
        } else {
          sum_day += 31;
        }
      }
      return sum_day;
    },
    getNowMonth() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      month = month > 9 ? month : "0" + month;
      var nowMonth = year + "/" + month;
      return nowMonth;
    },
    /**获取上一个月 */
    getPreMonth(date) {
      date = new Date(date);
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月

      return year + "/" + month + "/" + "01" + " 00:00:00";
    },
    getNextMonth(date) {
      date = new Date(date);
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let days = new Date(year, month, 0).getDate();
      console.log("111111111111113333:", days);
      return year + "/" + month + "/" + days + " 23:59:59";
    },
    getTitleDate(date) {
      date = new Date(date);
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let day = date.getDate(); // 日
      var hour = date.getHours(); // 时
      var minutes = date.getMinutes(); // 分
      var seconds = date.getSeconds(); //秒
      let sign1 = "/"
      var weekArr = [
        this.$t("Monday"),
        this.$t("Tuesday"),
        this.$t("Wednesday"),
        this.$t("Thursday"),
        this.$t("Friday"),
        this.$t("Saturday"),
        this.$t("Sunday")
      ];
      var week = weekArr[date.getDay() - 1];
      // 给一位数数据前面加 “0”
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (day >= 0 && day <= 9) {
        day = "0" + day;
      }
      if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
      }
      if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
      }
      if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
      }

      let dates = "";
      this.endTime = year + "/" + month + "/" + day + " " + hour + ":" + minutes + ":" + seconds
      this.titleDate = year + sign1 + month + sign1 + day + this.$t("day")

      // return dates;

    },
    handlLeft() {
      console.log("往左");
      // console.log("this.startTimeDate", this.startTimeDate);
      // console.log("this.endTimeDate", this.endTimeDate);
      if (this.type == "m") {
        this.endTime = new Date(
          new Date(this.endTime).getTime() - 24 * 60 * 60 * 1000
        );
        this.getTitleDate(this.endTime)
        // this.endTimeDate = new Date(
        //   new Date(this.startTimeDate).getTime() - 24 * 60 * 60 * 1000
        // );
        // this.titleDate = this.getTitleDate(this.startTimeDate);
        // // this.titleTime = currentdate.titleTime;
        // console.log("this.startTimeDate", this.startTimeDate);
      } else if (this.type == "y") {
        this.endTime = new Date(
          new Date(this.endTime).getTime() - 24 * 60 * 60 * 1000
        );
        this.getTitleDate(this.endTime)
      }
    },
    handlRight() {
      console.log("往右");
      if (new Date(
        new Date(this.endTime).getTime() + 24 * 60 * 60 * 1000
      ) > new Date().getTime()) {
        return
      }
      if (this.type == "m") {
        this.endTime = new Date(
          new Date(this.endTime).getTime() + 24 * 60 * 60 * 1000
        );
        this.getTitleDate(this.endTime)
        // this.endTimeDate = new Date(
        //   new Date(this.startTimeDate).getTime() - 24 * 60 * 60 * 1000
        // );
        // this.titleDate = this.getTitleDate(this.startTimeDate);
        // // this.titleTime = currentdate.titleTime;
        // console.log("this.startTimeDate", this.startTimeDate);
      } else if (this.type == "y") {
        this.endTime = new Date(
          new Date(this.endTime).getTime() + 24 * 60 * 60 * 1000
        );
        this.getTitleDate(this.endTime)
      }
    },
    getDate(type) {
      this.type = type;

      var date = new Date();
      var sign1 = "/";
      var sign2 = ":";
      var year = date.getFullYear(); // 年
      var month = date.getMonth() + 1; // 月
      var day = date.getDate(); // 日
      var hour = date.getHours(); // 时
      var minutes = date.getMinutes(); // 分
      var seconds = date.getSeconds(); //秒
      var weekArr = [
        this.$t("Monday"),
        this.$t("Tuesday"),
        this.$t("Wednesday"),
        this.$t("Thursday"),
        this.$t("Friday"),
        this.$t("Saturday"),
        this.$t("Sunday")
      ];
      var week = weekArr[date.getDay() - 1];
      // 给一位数数据前面加 “0”
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (day >= 0 && day <= 9) {
        day = "0" + day;
      }
      if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
      }
      if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
      }
      if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
      }
      if (type == "m") {

        this.titleDate =
          year +
          sign1 +
          month +
          sign1 +
          day +
          this.$t("day")
        this.endTime = year + "/" + month + "/" + day + " " + hour + ":" + minutes + ":" + seconds

      } else if (type == "y") {
        this.titleDate =
          year +
          sign1 +
          month +
          sign1 +
          day +
          this.$t("day")
        this.endTime = year + "/" + month + "/" + day + " " + hour + ":" + minutes + ":" + seconds
      }
    },
    handle(name) {
      console.log("name:", name)
      if (name == "m") {
        this.$router.push({ path: "/versionInfo", query: { 'active': "m" } });
      } else {
        this.$router.push({ path: "/WaistPosture", query: { 'active': "y" } });
      }
      // this.getDate(this.$route.query.active);
      // console.log("this.endTime", this.endTime)
    }
  },
  created() {
    this.getDate(this.$route.query.active);
    // this.titleTime = this.getDate("m").titleTime;
    // // console.log("this.startTime",this.startTime)
    // // console.log("this.startTime",this.endTime)
  }
};
export default mixin;
